﻿CREATE TABLE [Permissions] (
  [PermissionId] int NOT NULL  IDENTITY (38,1)
, [Name] nvarchar(50) NOT NULL
, [Description] nvarchar(500) NULL
, [Area] nvarchar(50) NOT NULL
);
GO
CREATE TABLE [RolesPermissions] (
  [RoleId] int NOT NULL
, [PermissionId] int NOT NULL
);
GO
CREATE TABLE [Pages] (
  [PageId] int NOT NULL  IDENTITY (30,1)
, [Title] nvarchar(250) NOT NULL CONSTRAINT uc_Title UNIQUE
, [Url] nvarchar(150)  NOT NULL CONSTRAINT uc_Url UNIQUE
, [DateCreated] datetime NOT NULL DEFAULT GetDate()
, [IsHomePage] bit NOT NULL DEFAULT 0
, [MetaDescription] nvarchar(250) NULL
, [MetaKeywords] ntext NULL
, [DateArchived] datetime NULL
, [ArchivedBy] int NULL
, [Layout] nvarchar(50) NULL
);
GO
CREATE TABLE [PageContent] (
  [ContentId] int NOT NULL  IDENTITY (36,1)
, [PageId] int NOT NULL
, [DateCreated] datetime NOT NULL DEFAULT GetDate()
, [Published] datetime NULL
, [Content] ntext NULL
, [CreatedBy] int NULL
, [PublishedBy] int NULL
);
GO
CREATE TABLE [Menus] (
  [MenuId] int NOT NULL  IDENTITY (6,1)
, [MenuName] nvarchar(100)  NOT NULL CONSTRAINT uc_MenuName UNIQUE
, [CssClass] nvarchar(100) NULL
, [Orientation] nvarchar(10) NULL
);
GO
CREATE TABLE [MenuItems] (
  [MenuItemId] int NOT NULL  IDENTITY (23,1)
, [MenuId] int NOT NULL
, [MenuText] nvarchar(50) NOT NULL
, [CssClass] nvarchar(50) NULL
, [Target] nvarchar(10) NULL
, [MenuOrder] int NULL DEFAULT 0
, [PageId] int NULL
);
GO
CREATE TABLE [Layers] (
  [LayerId] int NOT NULL  IDENTITY (5,1)
, [LayerName] nvarchar(50) NOT NULL
, [Description] nvarchar(500) NULL
, [Layout] nvarchar(50) NOT NULL
);
GO
CREATE TABLE [PagesInLayers] (
  [LayerId] int NOT NULL
, [PageId] int NOT NULL
);
GO
CREATE TABLE [HtmlWidgets] (
  [HtmlWidgetId] int NOT NULL  IDENTITY (4,1)
, [WidgetName] nvarchar(50) NOT NULL CONSTRAINT uc_WidgetName UNIQUE
, [Content] ntext NOT NULL
);
GO
CREATE TABLE [Forms] (
  [FormId] int NOT NULL  IDENTITY (2,1)
, [FormName] nvarchar(50)  NOT NULL CONSTRAINT uc_FormName UNIQUE
, [Legend] nvarchar(150) NOT NULL
, [SmtpServer] nvarchar(50) NOT NULL
, [SmtpPort] int NULL
, [SmtpUserName] nvarchar(50) NULL
, [SmtpPassword] nvarchar(50) NULL
, [FromAddress] nvarchar(50) NULL
, [SmtpEnableSsl] bit NULL
, [Subject] nvarchar(150) NULL
, [SendMessage] ntext NULL
, [SendErrorMessage] ntext NULL
, [ToAddress] nvarchar(50) NULL
, [ShowFormAfterSending] bit NULL DEFAULT 0
, [BeforeSendMessage] ntext NULL
);
GO
CREATE TABLE [Widgets] (
  [WidgetId] int NOT NULL  IDENTITY (28,1)
, [WidgetName] nvarchar(50) NULL
, [ZoneId] int NOT NULL
, [DisplayOrder] int NOT NULL DEFAULT 0
, [Theme] nvarchar(100) NOT NULL
, [CssClass] nvarchar(50) NULL
, [HtmlWidgetId] int NULL
, [LayerId] int NULL
, [Args] nvarchar(1000) NULL
, [MenuId] int NULL DEFAULT Null
, [FormId] int NULL
);
GO
CREATE TABLE [FieldDataTypes] (
  [DataTypeId] int NOT NULL  IDENTITY (10,1)
, [DataType] nvarchar(50) NOT NULL
, [Description] nvarchar(150) NULL
);
GO
CREATE TABLE [FormFields] (
  [FormFieldId] int NOT NULL  IDENTITY (7,1)
, [FormId] int NOT NULL
, [FieldName] nvarchar(50) NOT NULL
, [LabelText] nvarchar(50) NOT NULL
, [HelpText] ntext NULL
, [DataTypeId] int NOT NULL
, [Required] bit NULL
, [MinLength] int NULL
, [MaxLength] int NULL
, [CompareTo] int NULL
, [RequiredErrorMessage] nvarchar(150) NULL
, [MaxLengthErrorMessage] nvarchar(150) NULL
, [RangeErrorMessage] nvarchar(150) NULL
, [CompareToErrorMessage] nvarchar(150) NULL
, [DisplayOrder] int NULL
, [MinLengthErrorMessage] nvarchar(150) NULL
);
GO
ALTER TABLE [webpages_Roles] ADD [Description] ntext NULL;
GO